package com.markerhub.controller;


import com.markerhub.common.lang.Result;
import com.markerhub.entity.Category;
import com.markerhub.service.CategoryService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/manager-category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @RequiresRoles("root")
    @GetMapping("/categories")
    public Result listCategories() {
        return Result.succ(categoryService.list());
    }

    @RequiresRoles("root")
    @PostMapping("/category")
    public Result saveCategory(@RequestBody Category category) {
        categoryService.saveOrUpdate(category);
        return Result.succ("操作成功");
    }

    @RequiresRoles("root")
    @DeleteMapping("/category/{id}")
    public Result deleteCategory(@PathVariable Integer id) {
        categoryService.removeById(id);
        return Result.succ("删除成功");
    }
}
